package leetcode.hot100;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class number46 {
    static List<List<Integer>> list=new ArrayList<>();
    public static void main(String[] args) {
        permute(new int[]{1,2,3});
        list.forEach(i->{
            System.out.println(i);
        });
    }

    public static List<List<Integer>> permute(int[] nums) {
        dfs(0,nums);
        return list;
    }
    public static void dfs(int i,int[]nums){
        if(i==nums.length-1){
            list.add(Arrays.stream(nums).boxed().collect(Collectors.toList()));
        }
        for(int j=i;j<nums.length;j++){
            swap(nums,i,j);
            dfs(i+1,nums);
            swap(nums,i,j);
        }

    }
    public static void swap(int []nums,int i,int j){
        int temp=nums[i];
        nums[i]=nums[j];
        nums[j]=temp;
    }
}
